<extend name="Public/base"/>
<block name="body">
  <style>
    #sku_prp .form-item{
      float:left;
      width:200px;
    }
    h4.title{
      clear:both;
    }
    #help{
      background: #2181FF;
    }
  </style>
  <div class="main-title">
    <h2>{$data['id'] ? '编辑' : '新增'}商品</h2>
  </div>
  <div class="tab-wrap">
    <ul class="tab-nav nav">
      <li data-tab="tab0" class="current"><a href="javascript:;">基本信息</a> </li>
      <li data-tab="tab1"><a href="javascript:;">促销推荐</a></li>
      <li data-tab="tab2"><a href="javascript:;">补充信息</a></li>
      <li data-tab="tab3"><a href="javascript:;">铺货到抖音小店</a></li>
      <li data-tab="tab4"><a href="javascript:;">铺货到视频号小店</a></li>
      <li data-tab="tab5"><a href="javascript:;">铺货到Tiktop跨境</a></li>
      <li data-tab="tab6"><a href="javascript:;">铺货到shopee虾皮跨境</a></li>
    </ul>
  </div>

    <div class="item-field">
      <div class="tab-content">
        <form id="form" action="{:U('update')}" method="post" class="form-horizontal">
          <div class="tab-pane tab0 in">
            <div class="form-item cf">
              <label class="item-label">商品抓取<span class="check-tips">(支持<a href="https://show.1688.com/pinlei/industry/pllist.html?spm=a260j.12536015.jr60bfo3.26.2a15700etGRF6g&&sceneSetId=857&sceneId=27113&bizId=155765&adsSearchWord=T%E6%81%A4" target="_blank">1688</a>)</span></label>
              <div class="controls">
                <input type="text" class="text input-mid" style="width:40%" placeholder="请输入商品页的URL网址" id="sourceurl" name="sourceurl" value="{$data['sourceurl'] ? $data['sourceurl'] : ''}">
                <input type="button" class="btn btn-nav" id="collectbtn" name="collectbtn" value="一键获取">
                <input type="button" class="btn btn-nav" id="help" name="help" value="帮助">
                <textarea name="cookie" id="cookie" placeholder="cookie" style="padding-left:10px;width:40%;height:35px;display:none"></textarea>
              </div>
            </div>
            <!-- 基本信息开始 -->
            <h4 class="title"><i>1</i>商品基本信息  <if condition='$data.id gt 0'><a class="copyLink" href="https://shop.shante.me/Shop/Item/edit/id/{$data['id']}.html">[复制链接]</a></if></h4>
            <div class="form-item cf">
              <label class="item-label" style="float:left">商品分类</label>
              <div id="xxk" style="float:left;width:90%">
                <span class="xxk active" data-id="1">闪特</span>
                <span class="xxk" data-id="2">抖音</span>
                <span class="xxk" data-id="3">视频号</span>
                <span class="xxk" data-id="4">虾皮</span>
                <span style="width:200px;display: inline-block"><input type="text" name="search" id="searchcategory" value="" placeholder="输入搜索分类关键词"></span>
              </div>
              <div class="categoryxxk" style="clear:both">
                <div class="xxka" id="xxk1"><div class="cl"></div>
                  <div id="cateforyarr" id="cateforyarr1"></div>
                  <div class="controls" id="J_itemCategory" id="J_itemCategory1">加载中...</div>
                  <input type="hidden" value="" name="category" id="J_category">
                </div>
                <div class="xxka" id="xxk2">
                  <div id="cateforyarr2"></div><div class="cl"></div>
                  <div class="controls" id="J_itemCategory2">加载中...</div>
                  <input type="hidden" value="" name="category2" id="J_category2">
                  <if condition='$data.id gt 0'><input type="button" class="puhuo"  data-action="https://fxg.jinritemai.com/ffa/g/create" data-site="douyin" value="铺货"></if>
                  <button class="btn btn-return-collect ajax-post" <if condition='$data.id eq null'>disabled</if> type="submit" target-form="form-horizontal">保存</button>
                </div>
                <div class="xxka" id="xxk3">
                  <div id="cateforyarr3"></div><div class="cl"></div>
                  <div class="controls" id="J_itemCategory3">加载中...</div>
                  <input type="hidden" value="" name="category3" id="J_category3">
                  <if condition='$data.id gt 0'><input type="button" class="puhuo" name="puhuo3"  value="铺货"  data-action="https://channels.weixin.qq.com/shop/goods/category" data-site="weixin" value="铺货"></if>
                  <button class="btn btn-return-collect ajax-post" <if condition='$data.id eq null'>disabled</if> type="submit" target-form="form-horizontal">保存</button>
                </div>
              </div>
              <div class="xxka" id="xxk4">
                <div id="cateforyarr4"></div><div class="cl"></div>
                <div class="controls" id="J_itemCategory4">加载中...</div>
                <input type="hidden" value="" name="category4" id="J_category4">
                <if condition='$data.id gt 0'><input type="button" class="puhuo" name="puhuo4" value="铺货" data-action="https://seller.shopee.cn/portal/product/mtsku/new"  data-site="shopee" value="铺货"></if>
                <button class="btn btn-return-collect ajax-post" <if condition='$data.id eq null'>disabled</if> type="submit" target-form="form-horizontal">保存</button>
              </div>

            </div>

            <div class="form-item cf">
              <label class="item-label">店铺分类</label>
              <div class="controls">{$select_html}</div>
            </div>
            <div class="form-item cf">
              <label class="item-label">商品编号<span class="check-tips">（系统自动生成编号，可自行修改）</span></label>
              <div class="controls">
                <input type="text" class="text input-mid" name="number" value="{$data['number'] ? $data['number'] : create_uniqid_sn(4)}">
              </div>
            </div>
            <div class="form-item cf">
              <label class="item-label">商品名称<span class="check-tips">（折扣优惠信息将高亮显示在商品名称后面）</span></label>
              <div class="controls">
                <input type="text" class="text input-large" name="name" value="{$data.name}">
                <input type="text" class="text input-mid" name="subname" value="{$data.subname}" placeholder="折扣优惠等，高亮显示">
              </div>
            </div>
            <div class="form-item cf">
              <label class="item-label">商品品牌</label><!--yzs edit-->
              <div class="controls">
                  <select name="brand_id">
                    <option value="0">请选择</option>
                    <volist name="brand" id="vo">
                      <option value="{$vo['id']}" {eq name="vo.id" value="$data.brand_id"}selected{/eq}>{$vo['name']}</option>
                    </volist>
                  </select>
              </div>
            </div>
            <div class="form-item cf">
              <label class="item-label">商品简介<span class="check-tips">（简介、折扣、优惠等信息，显示在商品名称下方）</span></label>
              <div class="controls">
                <textarea name="summary" class="textarea input-large" rows="4">{$data.summary}</textarea>
              </div>
            </div>

              <!-- 商品标签 start  @author : wolfHua -->
              <label class="item-label">商品标签</label>
              <div class="form-item" id="sku_label" style="background: #fff;padding: 8px;border: 1px solid #ddd;">
                  <if condition="$data.id gt 0">
                      <div class="text-cancel"><img src="__IMG__/loading_icon.gif"/> 标签数据正在加载...</div>
                      <else/>
                      <div class="text-cancel">请先选择分类</div>
                  </if>
              </div>
              <!-- 商品标签 end -->


            <div class="form-item">
              <label class="item-label">价格与库存<span class="check-tips">（默认市场价为本地价的1.5倍）</span></label>
              <div class="controls">
                <div class="field-group">
                  <table>
                    <thead>
                      <tr>
                        <th>本店价</th>
                        <th>市场价</th>
                        <th>供应价</th>
                        <th>直播市场价</th>
                        <th>直播供应链底价</th>
                        <th>直播员利润提成</th>
                        <th>直播员单价</th>
                        <th>可帶貨數量</th>
                        <th>库存</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr>
                        <td><input class="text input-small" name="price" id="price" type="text" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" value="{$data.price}">
                          (元)</td>
                        <td><input class="text input-small" name="mprice" id="mprice" type="text" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" value="{$data.mprice}">
                          (元)</td>
                        <td><input class="text input-small" name="gprice" id="gprice" type="number" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" value="{$data.gprice}"> (元)</td>
                        <td><input class="text input-small" name="zprice" id="zprice" type="number" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" value="{$data.zprice}"> (元)</td>
                        <td><input class="text input-small" name="zlprice" id="zlprice" type="number" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" value="{$data.zlprice}"> (元)</td>
                        <td><input class="text input-small" name="ztrate" id="ztrate" type="number" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" value="{$data.ztrate}"> %</td>
                        <td><input class="text input-small" name="zbyprice" id="zbyprice" type="number" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" value="{$data.zbyprice}"> (元)</td>
                        <td><input class="text input-small" name="dqkdh" id="dqkdh" type="number" value="{$data.dqkdh}"></td>
                        <td><input class="text input-mini" name="stock" id="stock" type="text" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" value="{$data.stock}"></td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
            <!-- 重量 -->
            <div class="form-item">
              <label class="item-label">商品包装重量<span class="check-tips">（用于计算运费，务必统一单位为：<strong class="text-danger">千克kg</strong>）</span></label>
              <div class="controls">
                <input type="text" class="text input-small" name="weight"  id="weight" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" value="{$data.weight}">
                <span class="text-danger">kg</span> </div>
            </div>

            <if condition='C("START_POSITION")'>
            <h4 class="title"><i>2</i>设置可售区域</h4>
            <div class="form-item set_zone" style="background: #fff;padding:8px;margin-top: -6px;border: 1px solid #ddd">
           <div class="text-cancel"><img src="__IMG__/loading_icon.gif"/> 规格数据正在加载...</div>
            </div>
            </if>
            <h4 class="title"><i> <if condition='C("START_POSITION")'>4<else />3</if></i>商品规格</h4>
            <div class="form-item" style="background: #fff;padding:8px;margin-top: -6px;border: 1px solid #ddd" id="sku_spec">
              <if condition="$data.id gt 0">
                <div class="text-cancel"><img src="__IMG__/loading_icon.gif"/> 规格数据正在加载...</div>
                <else/>
                <div class="text-cancel">请先选择分类</div>
              </if>
            </div>
            <h4 class="title"><i>3</i>商品属性</h4>
            <div class="form-item" id="sku_prp">
              <if condition="$data.id gt 0">
                <div class="text-cancel"><img src="__IMG__/loading_icon.gif"/> 属性数据正在加载...</div>
                <else/>
                <div class="text-cancel">请先选择分类</div>
              </if>
            </div>
            <!-- 商品描述 -->
            <h4 class="title"><i><if condition='C("START_POSITION")'>5<else />4</if></i>商品描述</h4>
            <div class="form-item">
              <label class="item-label">商品图片<span class="check-tips">（请上传大小为800px * 800px的商品图片，选中已上传的图片拖动鼠标可对图片进行排序，第一张为封面图片）</span></label>
              <div class="controls"> {:hook('uploadImages', array('item_id' => $data['id'], 'name' => 'images', 'value' => $data['images'], 'thumb' => $data['thumb'], 'tpl' => 'baidu/thumbs'))} </div>
            </div>
            <div class="form-item">
              <label class="item-label">商品描述<span class="check-tips">（商品描述里插入的图片尺寸建议：宽度=800px，高度&lt;=1000px）</span></label>
              <div class="controls">
                <textarea name="intro">{$data.intro}</textarea>
                {:hook('adminArticleEdit', array('name' => 'intro','value' => $data['intro']))} </div>
            </div>
            <!--运费选择-->
            <h4 class="title"><i><if condition='C("START_POSITION")'>6<else />5</if></i>运费模板</h4>
            <div class="form-item">
              <!-- <label class="item-label">所在地</label>
              <div class="controls" id="J_area"></div> -->
              <label class="item-label">运费</label>
              <div class="controls">
                <label class="radio">
                  <input type="radio" value="1" name="transport_type">
                  固定运费</label>
                &nbsp; &nbsp;
                <input type="number" class="text input-small" name="freight" value="{$data['freight']}">
                <span>元</span> <br/>
                <br/>
                <notempty name="transport">
                <label class="radio"><input type="radio" value="2" name="transport_type">使用运费模板</label>&nbsp;&nbsp;<!--后面的这一块默认隐藏，选中后显示-->
                <select name="transport_id">
                  <option value="0">请选择</option>
                  <volist name="transport" id="vo">
                  <option value="{$vo['id']}">{$vo['title']}</option>
                  </volist>
                </select>
                </notempty>
              </div>
            </div>
            <div class="form-item cf">
              <label class="item-label">是否上架<span class="check-tips">（未上架的商品将不会在前台显示）</span></label>
              <div class="controls">
                <label class="radio">
                  <input type="radio" value="1" name="status">
                  是</label>
                <label class="radio">
                  <input type="radio" value="0" name="status">
                  否</label>
              </div>
            </div>
            <div class="form-item" style="display:none;">
              <div class="controls">
                <label>
                  <input type="checkbox" name="save_as_new_item" value="1">
                  另存为新商品 </label>
              </div>
            </div>
            <!-- 基本信息结束 -->
            <div class="form-item form-action cf">
              <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">保存</button>
              <a class="btn btn-return" href="{$Think.cookie.__forward__}">返 回</a>
              <input type="hidden" name="id" value="{$data.id|default=''}"/>
            </div>
          </div>
          <div class="tab-pane tab1">
            <!--促销推荐开始-->
            <div class="form-item">
              <label class="item-label">推荐位置</label>
              <div class="controls">
                <label class="checkbox"><input type="checkbox" value="1" name="is_hot">热卖</label>
                <label class="checkbox"><input type="checkbox" value="1" name="is_new">新品</label>
                <label class="checkbox"><input type="checkbox" value="1" name="is_promote">特价/抢购</label>
              </div>
            </div>
            <div class="form-item">
              <label class="item-label">购买返积分<span class="check-tips">（积分数量，请设置为数字）</span></label>
              <div class="controls">
                <input type="text" class="text input-mini" name="credit" value="{$data.credit|default=0}" placeholder="默认不返积分">
              </div>
            </div>
            <div class="form-item">
              <label class="item-label">商品排序<span class="check-tips">（请设置为数字，数字越小越靠前）</span></label>
              <div class="controls">
                <input type="text" class="text input-mini" name="sort" value="{$data.sort}">
              </div>
            </div>
            <div class="form-item">
              <label class="item-label">是否置顶<span class="check-tips">（请设置为数字，0为不置顶，大于0则置顶，数字越大越靠前）</span></label>
              <div class="controls">
                <input type="text" class="text input-mini" name="is_top" value="{$data.is_top}">
              </div>
            </div>
            <!--          <div class="form-item">
                        <label class="item-label">购买数<span class="check-tips">（可手动设置商品购买数，真实购买数将在此基础上累加）</span></label>
                        <div class="controls">
                          <input type="text" class="text input-mini" name="buynum" value="{$data.buynum|default=0}">
                        </div>
                      </div>
                      <div class="form-item">
                        <label class="item-label">收藏数<span class="check-tips">（可手动设置商品收藏数量，真实收藏数将在此基础上累加）</span></label>
                        <div class="controls">
                          <input type="text" class="text input-mini" name="favnum" value="{$data.favnum|default=0}">
                        </div>
                      </div>-->
            <!-- 限购 -->
            <div class="form-item">
              <label class="item-label">用户限购设置<span class="check-tips">（不限购请设为 0 件）</span></label>
              <div class="controls">
                <select name="quota_hours">
                  <option value="0">单订单</option>
                  <option value="24">每天</option>
                  <option value="168">每周</option>
                  <option value="720">每月</option>
                  <option value="8760">每年</option>
                  <option value="87600">每用户</option>
                </select>
                限购
                <input type="text" class="text input-mini text-center" name="quota_num" value="{$data.quota_num|default=0}">
                件 </div>
            </div>
            <div class="form-item cf">
              <label class="item-label">分销返现类型<span class="check-tips">（按比例或者固定金额）</span></label>
              <div class="controls">
                <label class="radio">
                  <input type="radio" value="0" name="sdp_type">
                  固定金额</label>
                <label class="radio">
                  <input type="radio" value="1" name="sdp_type">
                  商品售价比例</label>
              </div>
            </div>
            <div class="form-item cf">
              <label class="item-label">分销返现<span class="J_sdp_label">比例</span><span class="check-tips">（请输入分销返现<span class="J_sdp_label">比例</span>）</span></label>
              <div class="controls">
                <input type="text" class="text input-mini" name="sdp" value="<php> if(is_null($data['sdp'])){ echo C('ALL');}else{ echo $data['sdp'];}</php>">
                <span class="J_sdp_unit">%</span> </div>
            </div>
            <if condition="C('DIS_START')">
              <div class="form-item">
                <label class="item-label">推广返现比例 <span class="check-tips">（以商品总价为基准,0则不返现，空则使用默认配置中的返现）</span> </label>
                <div class="controls"> 一级代理：
                  <input type="text" class="text input-mini" name="sdp1" value='<php>if(is_null($data["sdp1"])){echo C("FIRISTNAME");}else{echo $data["sdp1"];}</php>'>
                  %&nbsp&nbsp
                  <if condition='C("DIS_CLASS") gt 1'> 二级代理：
                    <input type="text" class="text input-mini" name="sdp2" value='<php>if(is_null($data["sdp2"])){echo C("SECONDNAME");}else{echo $data["sdp2"];}</php>'>
                    % &nbsp&nbsp </if>
                  <if condition='C("DIS_CLASS") gt 2'> 三级代理：
                    <input type="text" class="text input-mini" name="sdp3" value='<php>if(is_null($data["sdp3"])){echo C("THIRDNAME");}else{echo $data["sdp3"];}</php>'>
                    % </if>
                </div>
              </div>
            </if>
            <if condition="$data">
              <div class="form-item">
                <label class="item-label">商品二维码 <span class="check-tips"> （右键另存或直接 <a href="javascript:;" id="printQRcode">打印</a>） </span> </label>
                <dif class="controls qrcode">
                  <if condition='$data.id gt 0'>
                  <div class="qrcode-area"> <img src="__ROOT__/{:C('QRCODE_CONFIG.rootPath')}Item/{$data.id}.png" id="qrcode" width="100" height="100" alt=""> </div>
                  </if>
                </dif>
              </div>
            </if>
            <!--促销推荐结束-->
            <div class="form-item form-action cf">
              <button class="btn submit-btn ajax-post" id="submit2" type="submit" target-form="form-horizontal">保存</button>
              <a class="btn btn-return" href="{$Think.cookie.__forward__}">返 回</a>
            </div>
          </div>
          <div id="tab2" class="tab-pane tab2">
                {$buchongzhiduan}
            <div class="form-item form-action cf">
              <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">保存</button>
              <a class="btn btn-return" href="{$Think.cookie.__forward__}">返 回</a>
              <input type="hidden" name="id" value="{$data.id|default=''}"/>
            </div>
          </div>
        </form>
        <div class="tab-pane tab3">
          <form id="form3" action="{:U('update')}" method="post" class="form-horizontal">
            <div class="form-item form-action cf">
              <button class="btn submit-btn ajax-post" id="submit3" type="button" target-form="form-horizontal">发布到抖音小店</button>
            </div>
          </form>
        </div>
        <div class="tab-pane tab4">
        <form id="form4" action="{:U('update')}" method="post" class="form-horizontal">
          <div class="form-item form-action cf">
            <button class="btn submit-btn ajax-post" id="submit4" type="button" target-form="form-horizontal">发布到视频号小店</button>
          </div>
        </form>
      </div>
        <div class="tab-pane tab5">
        <form id="form5" action="{:U('update')}" method="post" class="form-horizontal">
        </form>
      </div>
        <div class="tab-pane tab6">
        <form id="form6" action="{:U('update')}" method="post" class="form-horizontal">
          <div class="form-item form-action cf">
            <button class="btn submit-btn ajax-post" id="submit6" type="button" target-form="form-horizontal">发布到虾皮跨境店</button>
          </div>
        </form>
      </div>
  </div>
      </div>
    </div>

</block>
<block name="script"> 
  <script src="__JS__/jquery/jquery.loadtype.js?rand="+Math.random()></script>
  <script type="text/javascript" src="__JS__/jquery/jquery.printarea.js"></script> 
  <script type="text/javascript" src="__JS__/editor.js?r=321201"+Math.random()></script>
  <script type="text/javascript">
    $(function(){
      //导航高亮
      highlight_subnav("{:U('Item/add')}");
      // 导航切换
      showTab();
      //设置单选，复选，下拉菜单的值
      Core.setValue('quota_hours', '{$data.quota_hours|default = 0}');
      Core.setValue('store_cid', '{$data.store_cid|default = 0}');
      Core.setValue('brand_id', '{$data.brand_id|default = 0}');
      Core.setValue('transport_type', '{$data.transport_type|default = 1}');
      Core.setValue('transport_id', '{$data.transport_id|default = 0}');
      Core.setValue('is_recommend', '{$data.is_recommend|default = 0}');
      Core.setValue('is_new', '{$data.is_new|default = 0}');
      Core.setValue('is_hot', '{$data.is_hot|default = 0}');
      Core.setValue('is_promote', '{$data.is_promote|default = 0}');
      Core.setValue('status', '{$data.status|default = 0}');
      Core.setValue('sdp_type', '{$data.sdp_type|default = 0}');

      item.init('{$zoneinfo}');
      var zone_url = "{:U('Transport/get_zone')}" ;
      var item_id = "{$data.id}";
      var iscollect=false;
      <if condition='C("START_POSITION")'>
      item.handleZone();

      $.get(zone_url , {item_id:item_id}, function(data){
        $('.set_zone').html(data.html);
      });
      var _rate_ = $.parseJSON('{$zoneinfo}');
      $('#sku_spec').on('click' , '.zone_checkbox' ,function(){
        if($(this).is(':checked')){
          if(!$.isEmptyObject(_rate_)){
            if($('.spc_checkbox').length > 0 ){
              var mprice = $('input[name="price"]').val();
              $('#sku_spec>.zone-wrapper>table>tbody>tr').each(function(i ,el){
                var vals  = $(el).find('.spc_price>input').val();
                var names = $(el).find('.spc_price>input').attr('name');
                var temp1 = names.split('[');
                var temp2 = temp1[1].split(']');
                if(vals != '' && vals != null){
                  $.each(_rate_ , function(ii , ll){
                    var price = vals * ll.rate/100;
                    $('input[name="zone_price['+temp2[0]+'-zone'+ll.id+']"]').val(price);
                  })
                }else{
                  $('input[name="'+names+'"]').val(mprice);
                }
              })
            }else{
              var vals  = $('input[name="price"]').val();
                if(vals != '' && vals != null){
                  $.each(_rate_ , function(ii , ll){
                    var price = vals * ll.rate/100;
                    $('input[name="zone_price[zone'+ll.id+']"]').val(price);
                  })
              }
            }
            $(this).attr('checked',true);
          }
        }else{
          $(this).removeAttr('checked');
        }
      })
      </if>
      //商品分类   //yzs 商品修改 新增 上传 js
      console.log("{$data['cid_1']},{$data['cid_2']},{$data['cid_3']}");
      $('#J_itemCategory').loadtype({
        type: 'itemCategory',
        store_id: "",
        name1: 'cid_1',
        name2: 'cid_2',
        name3: 'cid_3',
        value1: "{$data['cid_1']}",
        value2: "{$data['cid_2']}",
        value3: "{$data['cid_3']}",
        changed: function(c1, c2, c3){
          var c_array = [];
          c1 && c_array.push($('select[name="cid_1"] option:selected').text());
          c2 && c_array.push($('select[name="cid_2"] option:selected').text());
          c3 && c_array.push($('select[name="cid_3"] option:selected').text());
          $('#J_category').val(c_array.join('>'));
          if(!iscollect) {

            var url = '{:U("Shop/ItemProperty/getProp?item_id=".$data["id"])}?cid_1=' + c1 + '&cid_2=' + c2 + '&cid_3=' + c3;
            var submit_checknumber = 0;
            $.get(url, function (data) {
              if (data != null) {
                $('#sku_prp').empty();
                $('#sku_prp').append(data);
              } else {
                $('#sku_prp').append('<div style="height:100px;line-height:100px;text-indent:20px;color:#f00;">您所选择的分类未绑定属性</div>');
              }
              submit_checknumber++;
              change_submit();
            });

            url = '{:U("Shop/ItemProperty/getProp?item_id=".$data["id"])}?type=specification&cid_1=' + c1 + '&cid_2=' + c2 + '&cid_3=' + c3;
            $.get(url, function (data) {
              if (data != null) {
                $('#sku_spec').empty();
                $('#sku_spec').append(data);
              } else {
                $('#sku_spec').append('<div style="height:100px;line-height:100px;text-indent:20px;color:#f00;">您所选择的分类未绑定规格</div>');
              }
              submit_checknumber++;
              change_submit();
            });
          }
          var change_submit = function(){
              if(submit_checknumber === 2){
                $('#submit').removeAttr('disabled');
              }
            };

          // if(!iscollect) {
          //   // 选择品牌
          //   url = '{:U("Shop/Item/getBrand?brand_id=".$data["brand_id"])}?cid_1=' + c1;
          //   $.get(url, function (data) {
          //     if (data != null) {
          //       $('select[name="brand_id"]').empty();
          //       $('select[name="brand_id"]').html(data);
          //     }
          //   });
          // }

            //选择标签 author:wolfHua
            url = '{:U("Shop/ItemLabel/getLabel?item_id=".$data["id"])}?cid_1=' + c1 + '&cid_2=' + c2 ;
            $.get(url,function(data){
                if(data != null){
                    $('#sku_label').empty();
                    $('#sku_label').append(data);
                }
            });

        }
      });

      $('#J_itemCategory2').loadtype1({
        type: 'itemCategoryDy',
        store_id: "",
        name1: 'cid_1_dy',
        name2: 'cid_2_dy',
        name3: 'cid_3_dy',
        name4: 'cid_4_dy',
        name5: 'cid_5_dy',
        value1: "{$data['cid_1_dy']}",
        value2: "{$data['cid_2_dy']}",
        value3: "{$data['cid_3_dy']}",
        value4: "{$data['cid_4_dy']}",
        value5: "{$data['cid_5_dy']}",
        changed: function(c1, c2, c3, c4, c5){
          var c_array = [];
          c1 && c_array.push($('select[name="cid_1_dy"] option:selected').text());
          c2 && c_array.push($('select[name="cid_2_dy"] option:selected').text());
          c3 && c_array.push($('select[name="cid_3_dy"] option:selected').text());
          c4 && c_array.push($('select[name="cid_4_dy"] option:selected').text());
          c5 && c_array.push($('select[name="cid_5_dy"] option:selected').text());
          $('#J_category2').val(c_array.join('>'));
        }
      });

      $('#J_itemCategory3').loadtype1({
        type: 'itemCategorySph',
        store_id: "",
        name1: 'cid_1_sph',
        name2: 'cid_2_sph',
        name3: 'cid_3_sph',
        name4: 'cid_4_sph',
        name5: 'cid_5_sph',
        value1: "{$data['cid_1_sph']}",
        value2: "{$data['cid_2_sph']}",
        value3: "{$data['cid_3_sph']}",
        value4: "{$data['cid_4_sph']}",
        value5: "{$data['cid_5_sph']}",
        changed: function(c1, c2, c3, c4, c5){
          var c_array = [];
          c1 && c_array.push($('select[name="cid_1_sph"] option:selected').text());
          c2 && c_array.push($('select[name="cid_2_sph"] option:selected').text());
          c3 && c_array.push($('select[name="cid_3_sph"] option:selected').text());
          c4 && c_array.push($('select[name="cid_4_sph"] option:selected').text());
          c5 && c_array.push($('select[name="cid_5_sph"] option:selected').text());
          $('#J_category3').val(c_array.join('>'));
        }
      });

      $('#J_itemCategory4').loadtype1({
        type: 'itemCategoryShopee',
        store_id: "",
        name1: 'cid_1_xiap',
        name2: 'cid_2_xiap',
        name3: 'cid_3_xiap',
        name4: 'cid_4_xiap',
        value1: "{$data['cid_1_xiap']}",
        value2: "{$data['cid_2_xiap']}",
        value3: "{$data['cid_3_xiap']}",
        value4: "{$data['cid_4_xiap']}",
        changed: function(c1, c2, c3, c4){
          var c_array = [];
          c1 && c_array.push($('select[name="cid_1_xiap"] option:selected').text());
          c2 && c_array.push($('select[name="cid_2_xiap"] option:selected').text());
          c3 && c_array.push($('select[name="cid_3_xiap"] option:selected').text());
          c4 && c_array.push($('select[name="cid_4_xiap"] option:selected').text());
          $('#J_category4').val(c_array.join('>'));
        }
      });

      const clipboardBtn = document.getElementById('collectbtn');
      clipboardBtn.addEventListener('click', async () => {
        try {
          if($("#sourceurl").val()=="") {
            const text = await navigator.clipboard.readText();
            if(/^http/.test(text)){
              $("#sourceurl").val(text);
            }
          }
        } catch (err) {
          console.error('无法获取剪切板内容:', err);
        }
      });


      $('#collectbtn').on('click',function(){
        let text="";
        if($("#sourceurl").val()=="") {
            layer.tips('商品网页链接不能为空！','#sourceurl',{
              tips: [3, '#000'],
              time: 3000,
              area: '300px'
            });
            return;
        }
        var index=layer.load();
        url = "https://shante.me/shantemecollect/getItem.php?url="+encodeURIComponent($("#sourceurl").val()) ;
        $("button.btn-return-collect").attr("disabled",true);
        $.post(url,{cookie:$("#cookie").val()},function(data){
          layer.close(index);
          debugger;
          if(data != null) {
            if(data['code']==0){
              layer.msg(data['msg']);
              return false;
            }
            iscollect=true;
            $("button.btn-return-collect").attr("disabled",false);
            $("select[name='cid_1']>option[value='" + data['cid_1'] + "']").prop("selected", true);
            $("select[name='cid_1']").trigger('change');
            $("select[name='cid_2']>option[value='" + data['cid_2'] + "']").prop("selected", true);
            $("select[name='cid_2']").trigger('change');
            $("select[name='cid_3']>option[value='" + data['cid_3'] + "']").prop("selected", true);
            $("select[name='cid_3']").trigger('change');
            $("input[name='name']").val(data['name']);
            $("input[name='number']").val(data['number']);
            $("textarea[name='intro']").val(data['intro']);
            $("textarea[name='summary']").val(data['summary']);
            $("input[name='sitehomeurl']").val(data['sitehomeurl']);
            $("input[name='companyName']").val(data['companyName']);
            $("input[name='offerUnit']").val(data['offerUnit']);
            $("textarea[name='cookie']").val(data['cookie']);
            $(".upload-img-box").html(data['uploadImgTemlate']);
            $("#sku_label").html("");
            $("#sku_prp").html(data['sku_prp']);
            $("select[name='store_cid']").html("<option value='"+data["store_class_id"]+"' selected>"+data["store_class"]+"</option>");
            $("select[name='brand_id']").html("<option value='"+data["brand_id"]+"' selected>"+data["brand"]+"</option>");
            $("#sku_spec").html(data["sku_spec"]);
            $("#stock").val(data["stock"]);
            $("#weight").val(data["weight"]);
            $("#ztrate").val(data["ztrate"]);
            $("#zbyprice").val(data["zbyprice"]);
            $("#dqkdh").val(data["dqkdh"]);
            if(data.hasOwnProperty("currSku")) {
              $("#price").val(data["currSku"]["price"]*2);
              $("#input[name=weight]").val(data["logistics_unitWeight"]);
              $("#mprice").val((data["currSku"]["price"] * 2.5).toFixed(1));
              $("#gprice").val((data["currSku"]["price"]*1).toFixed(1));
              $("#zprice").val((data["currSku"]["price"] * 2.2).toFixed(1));
              $("#zlprice").val((data["currSku"]["price"] * 2.2).toFixed(1));
            }
            $("iframe.ke-edit-iframe")[0].contentWindow.document.body.innerHTML = data['name']+data['intro']
            $("#tab2").html(data['buchongzhiduan']);
            $("#cateforyarr").html("")
            $("#cateforyarr2").html("")
            $("#cateforyarr3").html("")
            $("#cateforyarr4").html("")
            if((data['cateforyarr'])) {
              for (let i = 0; i < data['cateforyarr'].length; i++) {
                $("#cateforyarr").html($("#cateforyarr").html() + "<span class='xxkaa' data-text=" + data['cateforyarr'][i]['trees'] + ">" + data['cateforyarr'][i]['name'] + "</span> ");
              }
            }
            if((data['cateforyarr2'])) {
              for (let i = 0; i < data['cateforyarr2'].length; i++) {
                $("#cateforyarr2").html($("#cateforyarr2").html() + "<span class='xxkaa' data-text=" + data['cateforyarr2'][i]['trees'] + ">" + data['cateforyarr2'][i]['name'] + "</span> ");
              }
            }
            if((data['cateforyarr3'])) {
              for (let i = 0; i < data['cateforyarr3'].length; i++) {
                $("#cateforyarr3").html($("#cateforyarr3").html() + "<span class='xxkaa' data-text=" + data['cateforyarr3'][i]['trees'] + ">" + data['cateforyarr3'][i]['name'] + "</span> ");
              }
            }
            if((data['cateforyarr4'])) {
              for (let i = 0; i < data['cateforyarr4'].length; i++) {
                $("#cateforyarr4").html($("#cateforyarr4").html() + "<span class='xxkaa' data-text=" + data['cateforyarr4'][i]['trees'] + ">" + data['cateforyarr4'][i]['name'] + "</span> ");
              }
            }
          }
        },"jsonp");
        })


      $('#submit3').on('click',function(){
        localStorage.setItem("item_id",$("input[name=id]").val());
        $.get("http://localhost:3000/creategoods?site=douyin&item_id="+$("input[name=id]").val()+"&XDEBUG_SESSION_START=5432",function(){

        });
      })

      $('#submit4').on('click',function(){
        localStorage.setItem("item_id",$("input[name=id]").val());
        $.get("http://localhost:3000/creategoods?site=weixin&item_id="+$("input[name=id]").val()+"&XDEBUG_SESSION_START=5432",function(){

        });
      })

      $('#submit6').on('click',function(){
        localStorage.setItem("item_id",$("input[name=id]").val());
        $.get("http://localhost:3000/creategoods?site=shopee&item_id="+$("input[name=id]").val()+"&XDEBUG_SESSION_START=5432",function(){

        });
      })

      $("#cateforyarr").on('click',"span",function(){
        var n=$(this).attr("data-text").split(",");
        var that=this;
        $(".xxkaa").removeClass("active")
        $(this).addClass("active")
        $("select[name='cid_1']>option[value='" + n[0] + "']").prop("selected", true);
        $("select[name='cid_1']").trigger('change');
        $("select[name='cid_2']>option[value='" + n[1] + "']").prop("selected", true);
        $("select[name='cid_2']").trigger('change');
        $("select[name='cid_3']>option[value='" + n[2] + "']").prop("selected", true);
        $("select[name='cid_3']").trigger('change');
        $("input[name=search]").val($(this).text());
        $("input[name=search]").blur();
        $("#cateforyarr2>span.xxkaa").each(function(){
          if($(this).text()==$(that).text()){
            $(this).click().addClass("active")
          }
        })
        $("#cateforyarr3>span.xxkaa").each(function(){
          if($(this).text()==$(that).text()){
            $(this).click().addClass("active")
          }
        })
      })

      $("#cateforyarr2").on('click',"span",function(){
        var n=$(this).attr("data-text").split(",");
        $("#cateforyarr2 .xxkaa").removeClass("active")
        $(this).addClass("active")
        $("select[name='cid_1_dy']>option[value='" + n[0] + "']").prop("selected", true);
        $("select[name='cid_1_dy']").trigger('change');
        $("select[name='cid_2_dy']>option[value='" + n[1] + "']").prop("selected", true);
        $("select[name='cid_2_dy']").trigger('change');
        $("select[name='cid_3_dy']>option[value='" + n[2] + "']").prop("selected", true);
        $("select[name='cid_3_dy']").trigger('change');
        $("select[name='cid_4_dy']>option[value='" + n[3] + "']").prop("selected", true);
        $("select[name='cid_4_dy']").trigger('change');
        $("input[name=search]_dy").val($(this).text());
        $("input[name=search]_dy").blur();
      })

      $("#cateforyarr3").on('click',"span",function(){
        var n=$(this).attr("data-text").split(",");
        $("#cateforyarr3 .xxkaa").removeClass("active")
        $(this).addClass("active")
        $("select[name='cid_1_sph']>option[value='" + n[0] + "']").prop("selected", true);
        $("select[name='cid_1_sph']").trigger('change');
        $("select[name='cid_2_sph']>option[value='" + n[1] + "']").prop("selected", true);
        $("select[name='cid_2_sph']").trigger('change');
        $("select[name='cid_3_sph']>option[value='" + n[2] + "']").prop("selected", true);
        $("select[name='cid_3_sph']").trigger('change');
        $("select[name='cid_4_sph']>option[value='" + n[3] + "']").prop("selected", true);
        $("select[name='cid_4_sph']").trigger('change');
        $("input[name=search]").val($(this).text());
        $("input[name=search]").blur();
      })


      $("#cateforyarr4").on('click',"span",function(){
        var n=$(this).attr("data-text").split(",");
        $("#cateforyarr4 .xxkaa").removeClass("active")
        $(this).addClass("active")
        $("select[name='cid_1_xiap']>option[value='" + n[0] + "']").prop("selected", true);
        $("select[name='cid_1_xiap']").trigger('change');
        $("select[name='cid_2_xiap']>option[value='" + n[1] + "']").prop("selected", true);
        $("select[name='cid_2_xiap']").trigger('change');
        $("select[name='cid_3_xiap']>option[value='" + n[2] + "']").prop("selected", true);
        $("select[name='cid_3_xiap']").trigger('change');
        $("select[name='cid_4_xiap']>option[value='" + n[3] + "']").prop("selected", true);
        $("select[name='cid_4_xiap']").trigger('change');
        $("input[name=search]").val($(this).text());
        $("input[name=search]").blur();
      })

    });

    $("#help").on('click',function(){
      layer.open({
        type: 2, // 2 表示以 iframe 方式加载页面
        title: '抓取步骤',
        area: ['800px', '600px'], // 窗口大小
        content: 'https://shante.me/view/help'
      });
    })


    function spflzl(o){
       s=$("select[name=cid_1]").val()+","+$("select[name=cid_2]").val()+","+$("select[name=cid_3]").val();
       that=this;
       layer.open({
          type: 2, // 2 表示以 iframe 方式加载页面
          title: '栏目设置',
          area: ['60%', '600px'], // 窗口大小
          content: "__WWW__/Shop/ItemPublicCategory/edit.html?ids="+s,
          success: function (layero, index) {
            $("body",$("iframe:eq(1)",top.window.document)[0].contentWindow.document).attr("style","padding-left:0px");
            $(".sidebar",$("iframe:eq(1)",top.window.document)[0].contentWindow.document).attr("style","width:0px");
          }
       });
    }


    // 获取所有带有 copyLink 类的链接
    const copyLinkBtns = document.querySelectorAll('.copyLink');

    // 遍历每个链接，并为其添加点击事件监听器
    copyLinkBtns.forEach(link => {
      link.addEventListener('click', function(event) {
        event.preventDefault(); // 阻止默认的链接跳转行为
        // 获取当前链接的 data-href 属性值
        const linkHref = link.getAttribute('href');
        const textarea = document.createElement('textarea');
        textarea.value = linkHref;
        this.appendChild(textarea);
        textarea.focus();
        textarea.select();
        try {
          document.execCommand('copy');
          layer.tips('链接已复制到剪贴板: ' +linkHref, this, { area: '500px', time: 2000 });
        } catch (err) {
          console.error('备用复制方法也失败:', err);
        } finally {
          textarea.remove();
        }
      });
    });


  </script>
</block>
